import React from 'react';

import router from '../../../utils/routerDecorator';
import {get, post} from '../../../logic/api';
import ObjectList from '../../components/ObjectList';

import QiniuUploadimage from '../../components/QiniuUploadimage';
import styles from './main.less';
import Edit from './Edit';
import Del from './Del';
import Headimage from './Headimage';

@router('/site/cates')
export default class Cates extends React.Component {
  
  state = {

  }

  genColumns(){

  }

  async fetchData(){
    return await get('/admin/cate/list/main');
  }

  genColumns(){
    return [
      {title:'中文名称', dataIndex:'cname', width:'30%'},
      {title:'英文名称', dataIndex:'ename', width:'30%'},
      {title:'操作', width: '40%', render:(text, record)=>{
        if (record.parentId === 0){
          return <div className = {styles.operations}>
            <Edit text = "新建二级分类" 
                  record = {record}
                  fetchData = {async ()=>{
                    return {
                      data:{
                        parentId:record.id+"",
                        cname:"",
                        ename:"",
                        headimage:"",
                        describe:""
                      }
                    }
                  }} 
                  firstLevel = {['正装', '休闲', '鞋', '钟表', '配饰', '洁面', '皮具', '雪茄/烟', '衬衫', '面料']}
                  reload = {()=>{
                    ObjectList.Emitter.emit("reload");
                  }}
            />
            <Headimage record = {record}/>
          </div>
        }
        return <div className = {styles.operations2}>
          <Edit record = {record} reload = {
            ()=>{ObjectList.Emitter.emit("reload");}
          } firstLevel = {['正装', '休闲', '鞋', '钟表', '配饰', '洁面', '皮具', '雪茄/烟', '衬衫', '面料']}/>
          <Del record = {record} reload = {()=>{ObjectList.Emitter.emit("reload");}}/>
        </div>
      }}
    ]
  }

  render(){
    return <div>
      <ObjectList 
        columns = {this.genColumns()}
        fetchData = {this.fetchData}
      />
    </div>
  }

}